<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自动评教</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="../static/css/layui.css"/>
    <link rel="stylesheet" href="../static/css/style.css">
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script src='https://cas.paas.cdut.edu.cn/cas/deps/js/jsencrypt/3.0.0-rc.1/jsencrypt.min.js' type="text/javascript"></script>
    <!-- <script type="text/javascript" src="../static/js/control.js" ></script> -->
    <script type="text/javascript">
        var encryptEnabled = true;
        var encrypt = new JSEncrypt();
        var url = "https:\/\/cas.paas.cdut.edu.cn\/cas\/jwt\/publicKey";
        $.get(url, function(publicKey){
          // console.log(publicKey);
          encrypt.setPublicKey(publicKey);
        });
        </script>
</head>

<body>
    <div class="box">
        <div class="form-box">
            <h1>砚湖易办登录<span id="dh"></span></h1>
            <form id="form-dl">
                <div class="text-box">
                    <input class="text"  type="number" id="userNo" placeholder="请输入学号"/>
                </div>
                <div class="text-box">
                    <input class="text" type="password" id="pwd" placeholder="砚湖易办密码"/>
                </div>

                <button type="button" class="denglu" id="denglu">登 录</button>
                <script type="text/javascript">
                    var btn = document.getElementById("denglu")
                    btn.onclick = function() {
                        var userNo = String(document.getElementById("userNo").value)
                        var pwd = String(document.getElementById("pwd").value)
                        if(userNo == "")
                            alert("账号不能为空！")
                        else if(pwd == "")
                            alert("密码不能为空！")
                        else{
                            //var publicKey = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyor3CX6A6U4EoSHawtALiJoB0CkJnb/wmVkcVT5EmNupGVrVSeJo80ZAxsgd9S1CZVXxTXtJ7XjsqnzR64Qvrn+tdvj9Ck5k/6Tnp6HoKU/AQxA3tQ5Zqw6D6ihPOyVV4z4cdK5wjzEBNPhJuTjjzP4VQ4h4VseWNbfhXGK3vSes8oNn5Wwor9r1UbEJP/ZMHrDJxAcwe0GPvebAqEp4O5ZcTtWnq+/qkoUB6z/52EnCMltoPmuMC+o3fWdICBf4q70oSDClfuhLVi4mRT2K5UUH8fsxEe6oPtkvk9vVCCOZRmo0MXpXZiIqdZOtgcBzn/0mzoNd58KxeIy0ginjfwIDAQAB\n-----END PUBLIC KEY-----"

                            //encrypt.setPublicKey(publicKey)

                            en_pwd = encodeURIComponent(encrypt.encrypt(pwd))
                            $.ajax({
                                // 请求类型
                                type:"POST",
                                // 请求路径
                                url:"./gettoken",
                                // 请求数据
                                data:{
                                    userNo: userNo,
                                    pwd: en_pwd
                                },
                                //成功回调 
                                success:res=>{
                                    alert(res)
                                },
                                // 失败回调
                                error:err=>{
                                    alert(err)
                                }
                            })
                        }
                    }
                </script>
            </form>
    </div>

</body>
</html>